<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;

class UserNotify extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\UserNotify';

    //验证器
    protected string $validate = 'UserNotify';

    //关联模型
    protected array $hasOne = ['user'];

    protected array $append = ['status_name'];

    //自定义方法排序
    protected array $sort = ['id' => 'desc'];

    public function index(): string
    {
        return Builder::Table()
            ->addColumn(['field' => 'id', 'title' => 'ID', 'sort' => true, 'width' => 80])
            ->addColumn(['field' => 'uid', 'title' => '相关会员', 'templet' => '#_userTpl', 'width' => 240])
            ->addColumn(['field' => 'title', 'title' => '标题', 'modify' => '2,input'])
            ->addColumn(['field' => 'content', 'title' => '详情', 'modify' => '2,editor', 'templet' => '#editorTpl'])
            ->addColumn(['field' => 'status_name', 'title' => '状态'])
            ->addColumn(['field' => 'create_time', 'title' => '通知时间'])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 120])
            ->addRightButtons(['delete'])
            ->addTopButtons(['add' => ['size' => '60%']])
            ->addSearch([
                ['title', '标题', 'input,Like'],
                ['uid', '会员编号/昵称/手机号', 'input,Like', '', '\app\common\model\User', 'code|nickname|mobile,id']
            ])
            ->fetch();
    }

    public function add($tpl = 'user_notify/add'): string
    {
        return parent::add($tpl);
    }
}